<template>
  <a-modal title='添加提成政策' v-if='modalVisible' :visible='modalVisible' width='650px' @cancel='handleCancel' @ok='handleSubmit'>
    <f-form ref='form' :action='api.bpb' :form-key='this.formItem.policyBonusId' @success='handleCancel'>
      <f-form-item label='部门' type='select' name='deptId' required :showSearch='true'  :data='api.dept.list' label-key='deptName' value-key='deptId' :value.sync='formItem.deptId' :params='queryParam' @change='deptChange' />
      <f-form-item label='业务员' ref='saleMan' type='select' name='saleManId' :value.sync='formItem.saleManId' :data='api.saleMan.list' valueKey='saleManId' label-key='saleManName' :required='true' :params='loadSaleManParams' :autoLoad='autoLoad' v-show='formItem.deptId' />
      <f-form-item label='提成金额' name='bonusAmount' type='number' :precision='3' data-type='number' required :value='formItem.bonusAmount' />
      <f-form-item label='开始日期' name='beginDate' type='date' required :value='formItem.beginDate' />
      <f-form-item label='结束日期' name='endDate'  type='date' :value='formItem.endDate' />
      <f-form-item label='备注' name='remark'  :value='formItem.remark' />
    </f-form>
  </a-modal>
</template>
<script>
import api from "../../../../js/api"

export default {
  name: "policyBonusForm",
  props: {
    policyDrugId: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      refs: this.$refs,
      api: Object.assign(api, this.api),
      isAdd: true,//是否是添加模式
      formModal: false,
      fileIds: [],//上传文件ID
      loaded: false,//是否加载完成
      modalVisible: false,
      loadSaleManParams: {
        deptId: null
      },
      queryParam:{
        isFlp:1
      },
      autoLoad: false,
      bodyStyle: {
        height: "530px",
        overflow: "hidden",
        overflowY: "scroll"
      },
      formItem: this.getFormItem()
    }
  },
  methods: {
    getFormItem() {
      return {
        policyBonusId: null,
        deptId: null,
        saleManId: null,
        bonusAmount: null,
        beginDate: null,
        endDate: null,
        remark: null
      }
    },
    openModal(data) {
      this.isEdit = false
      if (data && data.policyBonusId) {
        this.isEdit = true
        this.formItem = data
        this.loadSaleManParams.deptId = data.deptId
        this.autoLoad = true
      } else {
        this.formItem = {}
        this.autoLoad = false
      }
      this.modalVisible = true
    },
    handleCancel() {
      this.modalVisible = false
    },
    deptChange(value) {
      this.loadSaleManParams.deptId = value
      this.$refs.saleMan.initData(this.loadSaleManParams)
      //清除已选择销售
      this.$refs.form.resetField("saleManId")
    },
    //提交表单
    handleSubmit() {
      this.$refs.form.submit({ policyDrugId: this.policyDrugId }, () => {
        this.$emit("success")
      })
    }
  },
  created() {
  },
  components: {}
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
